#include "thread.h"

int makeMysql(MYSQL *mysql){
    mysql=mysql_init(NULL);

    MYSQL *ret = mysql_real_connect(mysql,
                                    "localhost","root","123456",
                                    "diskMysql",
                                    0,NULL,0
                                   );
    if(!ret){
        fprintf(stderr,"mysql_real_connect:%s\n", mysql_error(mysql));
        return -1; 
    }
    //用户表
    char user[]="create table user(ID int auto_increment,"
        "name varchar(20),"//用户名
        "salt varchar(50),"//用户盐值
        "ciphertext varchar(100),"//用户密文密码
        "tomb int," //存活状态
        "nature varchar(50),"//预设属性
        "primary key(ID));";
    int qret=mysql_query(mysql,user);
    if(!qret){
        fprintf(stderr,"mysql_query:%s\n", mysql_error(mysql));
        return -1; 
    }
    //目录文件表
    char df_mes[]="create table df_mes(ID int auto_increment,"
                    "fileName varchar(256),"//文件/目录名
                    "path varchar(256),"//文件/目录路径
                    "user varchar(50),"//所有者用户名
                    "parID int,"//父目录ID
                    "md5 varchar(50),"//MD5码(只有文件拥有)
                    "tomb int,"//存活状态
                    "nature varcahr(50),"
                    "primary key(ID),"
                    "UNIQUE KEY unique_columns(path,user));";
    
    int dfret=mysql_query(mysql,df_mes);
    if(!dfret){
        fprintf(stderr,"mysql_query:%s\n", mysql_error(mysql));
        return -1; 
    }

    return 0;
}
